load("//bzl:cpp_library.bzl", "cpp_library")

package(default_visibility = ["//visibility:public"])

cpp_library(
    name = "exception_abi",
    hdrs = ["ExceptionAbi.h"],
)

cpp_library(
    name = "exception_counter",
    srcs = ["ExceptionCounterLib.cpp"],
    hdrs = ["ExceptionCounterLib.h"],
    deps = [
        ":exception_tracer_base",
        ":exception_tracer_callbacks",
        ":stacktrace",
        "//folly:range",
        "//folly:synchronized",
        "//folly:thread_local",
        "//folly/experimental/symbolizer",
        "//folly/hash:spooky_hash_v2",
        "//folly/synchronization:rw_spin_lock",
    ],
)

cpp_library(
    name = "exception_tracer",
    srcs = ["ExceptionStackTraceLib.cpp"],
    deps = [
        ":exception_abi",
        ":exception_tracer_base",
        ":exception_tracer_callbacks",
        ":stacktrace",
        "//folly/experimental/symbolizer",
    ],
)

cpp_library(
    name = "exception_tracer_base",
    srcs = ["ExceptionTracer.cpp"],
    hdrs = ["ExceptionTracer.h"],
    linkopts = select({
        "@platforms//os:linux": ["-ldl"],
        "//conditions:default": [],
    }),
    deps = [
        ":exception_abi",
        ":stacktrace",
        "//folly:cpp_attributes",
        "//folly:portability",
        "//folly:string",
        "//folly/experimental/symbolizer",
        "//folly/portability:config",
        "@glog",
    ],
)

cpp_library(
    name = "exception_tracer_callbacks",
    srcs = ["ExceptionTracerLib.cpp"],
    hdrs = ["ExceptionTracerLib.h"],
    linkopts = select({
        "@platforms//os:linux": ["-ldl"],
        "//conditions:default": [],
    }),
    deps = [
        "//folly:indestructible",
        "//folly:portability",
        "//folly:shared_mutex",
        "//folly:synchronized",
    ],
)

cpp_library(
    name = "stacktrace",
    srcs = ["StackTrace.cpp"],
    hdrs = ["StackTrace.h"],
    deps = [
        "//folly:portability",
        "//folly/experimental/symbolizer:stack_trace",
    ],
)

cpp_library(
    name = "smart_exception_tracer_singleton",
    srcs = [
        "SmartExceptionTracerSingleton.cpp",
    ],
    hdrs = [
        "SmartExceptionTracerSingleton.h",
    ],
    deps = [
        ":stacktrace",
        "//folly:synchronized",
        "//folly/container:f14_hash",
    ],
)

cpp_library(
    name = "smart_exception_stack_trace_hooks",
    srcs = [
        "SmartExceptionStackTraceHooks.cpp",
    ],
    deps = [
        ":exception_tracer_callbacks",
        ":smart_exception_tracer_singleton",
        "//folly/experimental/symbolizer",
    ],
)

cpp_library(
    name = "smart_exception_tracer",
    srcs = ["SmartExceptionTracer.cpp"],
    hdrs = ["SmartExceptionTracer.h"],
    deps = [
        ":exception_tracer_base",
        ":exception_tracer_callbacks",
        ":smart_exception_tracer_singleton",
        ":stacktrace",
        "//folly:exception_wrapper",
        "//folly:map_util",
        "//folly:scope_guard",
        "//folly:synchronized",
        "//folly/container:f14_hash",
        "//folly/experimental/symbolizer",
        "//folly/lang:exception",
        "@glog",
    ],
)
